package com.bmslz.monitor.base.dto;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bmslz.monitor.base.util.StringUtils;
import com.bmslz.monitor.base.entity.User;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

/**
 * @Description: 用户搜索入参
 * @Author: bobo
 * @Date: 2025-08-23
 * @Version: V1.0
 */
@Data
public class UserSearchDto {
    @ApiModelProperty(value = "用户ID")
    private String id;//用户ID
    @ApiModelProperty(value = "用户名")
    private String username;//用户名
    @ApiModelProperty(value = "角色")
    private String role;//角色
    @ApiModelProperty(value = "真实姓名")
    private String name;//真实姓名
    @ApiModelProperty(value = "真实姓名")
    /**套餐结束时间*/
    private List<String> orderCloseTime;//套餐结束时间

    public LambdaQueryWrapper<User> wrapper() {
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNotEmpty(id), User::getId, id);
        wrapper.like(StringUtils.isNotEmpty(username), User::getUsername, username);
        wrapper.eq(StringUtils.isNotEmpty(role), User::getRole, role);
        wrapper.like(StringUtils.isNotEmpty(name), User::getName, name);
        wrapper.orderByDesc(User::getCreateTime);
        if (orderCloseTime != null && orderCloseTime.size() == 1) {
            wrapper.ge(StringUtils.isNotEmpty(orderCloseTime.get(0)), User::getOrderCloseTime, orderCloseTime.get(0));
        }
        if (orderCloseTime != null && orderCloseTime.size() == 2) {
            wrapper.le(StringUtils.isNotEmpty(orderCloseTime.get(1)), User::getOrderCloseTime, orderCloseTime.get(1));
        }
        return wrapper;
    }
}
